home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / cdity / availmem2.lha / AvailMem2 / src / AvailMem2.s < prev    next >
Text File  |  1992-09-02  |  5KB  |  211 lines

  1.  
  2. ;Program History:
  3.  
  4. ;2.0ßeta0.1:
  5. ;    Wrote simple startup and closedown code, easily callable
  6. ;    like procedures.
  7.  
  8.     * program includes
  9.  
  10.     include    "AvailMem2_gui.i"
  11.  
  12.     incdir    "!includes:OS3.0"
  13.  
  14.     include    "exec/exec.i"
  15.     include    "dos/dos.i"
  16.     include    "dos/dosextens.i"
  17.     include    "graphics/gfx.i"
  18.     include    "intuition/intuition.i"
  19.     include    "libraries/commodites.i"
  20.  
  21.     incdir    "!includes:LVO"
  22.  
  23.     include    "exec_lib.i"
  24.     include    "dos_lib.i"
  25.     include    "graphics_lib.i"
  26.     include    "intuition_lib.i"
  27.  
  28.     * program exports
  29.  
  30.     public    _GadToolsBase
  31.     public    _IntuitionBase
  32.     public    _GfxBase
  33.     public    _SysBase
  34.  
  35.     * program structures
  36.  
  37.     * program defines
  38.  
  39. _SysBase        equ    (4).w    ;execbase constant
  40.  
  41. KICKVER            equ    37    ;require OS2.0+
  42. CONFVER            equ    1    ;config-version
  43.  
  44.     section    code,code        ;availmem code section
  45.  
  46. prg_Startup
  47.  
  48.     move.l    (4).w,a6        ;put execbase in a6
  49.     sub.l    a1,a1            ;clear a1
  50.     jsr    _LVOFindTask(a6)    ;find this task
  51.     move.l    d0,ptr_ThisTask        ;store taskptr
  52.  
  53.     move.l    ptr_ThisTask,a4        ;put pointer to task in a4
  54.     tst.l    pr_CLI(a4)        ;check if started from CLI
  55.     bne    .StartedFromCLI        ;skip if launched from CLI
  56.  
  57.     lea.l    pr_MsgPort(a4),a0    ;get ptr to msgport
  58.     jsr    _LVOWaitPort(a6)    ;wait for msg-port
  59.     lea.l    pr_MsgPort(a4),a0    ;get ptr to msgport
  60.     jsr    _LVOGetMsg(a6)        ;get waiting startup-message
  61.     move.l    d0,ptr_StartupMsg    ;store wbmessage
  62.  
  63. .StartedFromCLI
  64.  
  65.     move.l    (4).w,a6        ;put execbase in a6
  66.     lea.l    _DosName,a1        ;get ptr to dos.library
  67.     move.l    #KICKVER,d0        ;put kick version in d0
  68.     jsr    _LVOOpenLibrary(a6)    ;open dos.library
  69.     move.l    d0,_DosBase        ;store library base
  70.     beq    prg_Fail        ;bail out if failure
  71.  
  72.     move.l    (4).w,a6        ;put execbase in a6
  73.     lea.l    _GfxName,a1        ;get ptr to graphics.library
  74.     move.l    #KICKVER,d0        ;put kick version in d0
  75.     jsr    _LVOOpenLibrary(a6)    ;open graphics.library
  76.     move.l    d0,_GfxBase        ;store library base
  77.     beq    prg_Fail        ;bail out if failure
  78.  
  79.     move.l    (4).w,a6        ;put execbase in a6
  80.     lea.l    _IntuitionName,a1    ;get ptr to intuition.library
  81.     move.l    #KICKVER,d0        ;put kick version in d0
  82.     jsr    _LVOOpenLibrary(a6)    ;open intuition.library
  83.     move.l    d0,_IntuitionBase    ;store library base
  84.     beq    prg_Fail        ;bail out if failure
  85.  
  86.     move.l    (4).w,a6        ;put execbase in a6
  87.     lea.l    _GadToolsName,a1    ;get ptr to gadtools.library
  88.     move.l    #KICKVER,d0        ;put kick version in d0
  89.     jsr    _LVOOpenLibrary(a6)    ;open gadtools.library
  90.     move.l    d0,_GadToolsBase    ;store library base
  91.     beq    prg_Fail        ;bail out if failure
  92.  
  93.     tst.l    ptr_StartupMsg        ;check if launched from WB
  94.     beq    .NoDirWaiting        ;skip if launched from CLI
  95.  
  96.     move.l    _DosBase,a6        ;put dosbase in a6
  97.     move.l    ptr_StartupMsg,a2    ;get ptr to wbmessage
  98.     move.l    sm_ArgList(a2),a2    ;get ptr to wbstartup-message
  99.     move.l    wa_Lock(a2),d1        ;get currentdir lock
  100.     jsr    _LVOCurrentDir(a6)    ;set current directory
  101.  
  102. .NoDirWaiting
  103.  
  104.     jsr    SetupScreen        ;initialize screen
  105.     tst.l    d0            ;check if init worked
  106.     bne    prg_Fail        ;bail out if failure
  107.  
  108. prg_Main
  109.  
  110.  
  111. prg_CloseDown
  112.  
  113.     jsr    CloseResizeWindow    ;close resize window
  114.     jsr    CloseSettingsWindow    ;close settings window
  115.     jsr    CloseMemoryDisplayWindow;close main window
  116.     jsr    CloseDownScreen        ;deinitalize screen
  117.  
  118.     tst.l    _GadToolsBase        ;check if gadtools.library open
  119.     beq    .no_gadtoolsbase    ;skip if opening failed
  120.  
  121.     move.l    _GadToolsBase,a6    ;put gadtoolsbase in a6
  122.  
  123.     move.l    a6,a1            ;put gadtoolsbase in a1
  124.     move.l    (4).w,a6        ;put execbase in a6
  125.     jsr    _LVOCloseLibrary(a6)    ;close gadtools.library
  126.     move.l    #0,_GadToolsBase    ;reset library base
  127.  
  128. .no_gadtoolsbase
  129.  
  130.     tst.l    _IntuitionBase        ;check if intuition.library open
  131.     beq    .no_intuitionbase    ;skip if opening failed
  132.  
  133.     move.l    _IntuitionBase,a6    ;put intuitionbase in a6
  134.  
  135.     move.l    a6,a1            ;put intuitionbase in a1
  136.     move.l    (4).w,a6        ;put execbase in a6
  137.     jsr    _LVOCloseLibrary(a6)    ;close intuition.library
  138.     move.l    #0,_IntuitionBase    ;reset library base
  139.  
  140. .no_intuitionbase
  141.  
  142.     tst.l    _GfxBase        ;check if graphics.library open
  143.     beq    .no_gfxbase        ;skip if opening failed
  144.  
  145.     move.l    _GfxBase,a6        ;put gfxbase in a6
  146.  
  147.     move.l    a6,a1            ;put gfxbase in a1
  148.     move.l    (4).w,a6        ;put execbase in a6
  149.     jsr    _LVOCloseLibrary(a6)    ;close graphics.library
  150.     move.l    #0,_GfxBase        ;reset library base
  151.  
  152. .no_gfxbase
  153.  
  154.     tst.l    _DosBase        ;check if dos.library open
  155.     beq    .no_dosbase        ;skip if opening failed
  156.  
  157.     move.l    _DosBase,a6        ;put dosbase in a6
  158.  
  159.     move.l    a6,a1            ;put dosbase in a1
  160.     move.l    (4).w,a6        ;put execbase in a6
  161.     jsr    _LVOCloseLibrary(a6)    ;close dos.library
  162.     move.l    #0,_DosBase        ;reset library base
  163.  
  164. .no_dosbase
  165.  
  166.     tst.l    ptr_StartupMsg        ;check if message saved
  167.     beq    .NoWBMessage        ;skip if launched from CLI
  168.  
  169.     move.l    (4).w,a6        ;put execbase in a6
  170.     jsr    _LVOForbid(a6)        ;Forbid multitasking (No permit needed)
  171.  
  172.     move.l    ptr_StartupMsg,a1    ;put wbmessage in a1
  173.     jsr    _LVOReplyMsg(a6)    ;reply wbmessage
  174.  
  175. .NoWBMessage
  176.  
  177.     move.l    prg_Error,d0        ;put exitcode in d0
  178.     rts                ;exit program
  179.  
  180. prg_Fail
  181.     move.l    #20,prg_Error        ;set program error
  182.     bra    prg_CloseDown        ;quit program
  183.  
  184. * subroutines
  185.  
  186.     section    data,data
  187.  
  188. _DosName        dc.b    "dos.library",0
  189. _GfxName        dc.b    "graphics.library",0
  190. _IntuitionName        dc.b    "intuition.library",0
  191. _GadToolsName        dc.b    "gadtools.library",0
  192.  
  193.     section    bss,bss            ;availmem bss sections
  194.  
  195. * library bases
  196.  
  197. _DosBase        ds.l    1
  198. _GfxBase        ds.l    1
  199. _IntuitionBase        ds.l    1
  200. _GadToolsBase        ds.l    1
  201.  
  202. * program variables
  203.  
  204. ptr_ThisTask        ds.l    1
  205. ptr_StartupMsg        ds.l    1
  206. prg_Error        ds.l    1
  207.  
  208. * program static structs
  209.  
  210. ptr_CxPort        ds.l    1
  211.